<?php

$db[dbname] = "pajak";
$db[user] = "nksimpro_baru";
$db[password] = "nksimpro_baru";
$db[host] = "localhost";

$bulan[1]="Jan";
$bulan[2]="Feb";
$bulan[3]="Mar";
$bulan[4]="Apr";
$bulan[5]="May";
$bulan[6]="Jun";
$bulan[7]="Jul";
$bulan[8]="Aug";
$bulan[9]="Sep";
$bulan[10]="Oct";
$bulan[11]="Nov";
$bulan[12]="Des";

function combo_bulan($nama,$sel,$all=""){
	global $bulan;
	$txtout="<select id=$nama name=$nama style=\"background-color: #FFFFFF\" class=\"tombol\">";
	if($all<>""){
		$txtout .= "<option value=-1>All</option>";
	}
	for ($i=1;$i<=12;$i++){
		if ($i==$sel){
			$tulis =" selected";
		}
		$txtout .= "<option value=$i $tulis>".$bulan[$i]."</option>";
		$tulis = "";
	}
	$txtout .= "</select>";
	return $txtout;
}

function combo_tanggal($nama,$sel,$awal,$akhir){
	$txtout="<select id=$nama name=$nama style=\"background-color: #FFFFFF\" class=\"tombol\">";
	for ($i=$awal;$i<=$akhir;$i++){
		if ($i==$sel){
			$tulis =" selected";
		}
		$txtout .= "<option value=$i $tulis>".$i."</option>";
		$tulis = "";
	}
	$txtout .= "</select>";
	return $txtout;
}

function combo_array($nama,$arr_nilai,$sel){
		$txtout.="<select id=$nama name=$nama style=\"background-color: #FFFFFF\" class=\"tombol\">";
		while(list($key,$nilai)=each($arr_nilai)){
			if($nilai==$sel){
				$txtout.="<option value='$nilai' selected>$nilai</option>";
			}else{
				$txtout.="<option value='$nilai'>$nilai</option>";
			}
		}
		$txtout.="</select>";
		return $txtout;
	}

function ctr_array($arr){
	echo "<pre>";
	print_r($arr);
	echo "</pre>";
}
function dbresult($sql){
	global $conn;
	global $db;
	if(!isset($conn)){
		while(list($key,$isi)=each($db)){
			$opt .= "$key=$isi ";
		}
		$conn = pg_connect($opt);
	}
	//echo $sql."<br>";
	if(!$result = pg_exec($conn, $sql)){
		echo "Proses ke database gagal";
		pg_errormessage($conn);

		echo $sql."<br>";
	}
	return $result;
}


//function dbresult($sql){
//	global $conn;
//	global $db;
//	if(!isset($conn)){
//                //$conn = odbc_connect("Driver={PostgreSQL ODBC Driver(UNICODE)};Server=localhost;Database=$db[dbname]","$db[user]","$db[password]");
//		$conn = pg_connect("$db[dbname]","$db[user]","$db[password]");
//	}
//	if(!$result = pg_exec($conn, $sql)){
//		echo "Proses ke database gagal";
//		echo "<br>$sql<br>";
//                pg_errormessage($conn);
//	}
//	//echo "<br>$sql<br>";
//	return $result;
//}

function check_pass(){
	global $cusername;
	if($cusername!=""){

	}else{
		//header("Location: http://192.168.0.13/keunindya/index.php");
            header("Location: index.php");
	}
}

function baca_permisi($sub_f_id){
	global $permisi;
	global $cuserid;
	global $st_level_user;
	$sql="select * from tbl_user a inner join tbl_menu_peran b on a.level_akses=cast(b.id_peran as bigint) where a.user_id=$cuserid and b.sub_f_id=$sub_f_id";
	$res=dbresult($sql);//echo "$sql<br>";
	$jml=pg_num_rows($res);
	if($jml>0){
		$r=pg_fetch_array($res);
		switch($r[menu_access]){
			case 5:
					$permisi["add"]="izin";
					$permisi["edit"]="izin";
					$permisi["delete"]="izin";
					$permisi["access"]="izin";
					$permisi["copy"]="izin";
					$permisi["save"]="izin";
					$permisi["print"]="izin";
					$permisi["approve"]="izin";
					break;
					//AKSES ALL
			case 4:
					$permisi["add"]="izin";
					$permisi["edit"]="izin";
					$permisi["delete"]="izin";
					$permisi["access"]="izin";
					$permisi["copy"]="tolak";
					$permisi["save"]="izin";
					$permisi["print"]="izin";
					$permisi["approve"]="tolak";
					break;
					//AKSES READ/WRITE
			case 3:
					$permisi["add"]="tolak";
					$permisi["edit"]="izin";
					$permisi["delete"]="tolak";
					$permisi["access"]="izin";
					$permisi["copy"]="tolak";
					$permisi["save"]="tolak";
					$permisi["print"]="tolak";
					$permisi["approve"]="tolak";
					break;
					//AKSES READ/EDIT
			case 2:
					$permisi["add"]="tolak";
					$permisi["edit"]="tolak";
					$permisi["delete"]="tolak";
					$permisi["access"]="izin";
					$permisi["copy"]="tolak";
					$permisi["save"]="tolak";
					$permisi["print"]="izin";
					$permisi["approve"]="tolak";
					break;
					//AKSES READ
			case 1:
					$permisi["add"]="tolak";
					$permisi["edit"]="tolak";
					$permisi["delete"]="tolak";
					$permisi["access"]="tolak";
					$permisi["copy"]="tolak";
					$permisi["save"]="tolak";
					$permisi["print"]="tolak";
					$permisi["approve"]="tolak";
					break;
					//AKSES NOT ACCESS
			case 0:
					$permisi["add"]="tolak";
					$permisi["edit"]="tolak";
					$permisi["delete"]="tolak";
					$permisi["access"]="tolak";
					$permisi["copy"]="tolak";
					$permisi["save"]="tolak";
					$permisi["print"]="tolak";
					$permisi["approve"]="tolak";
					break;
					//KOSONG
		}
	}
}

function list_voucher($sql,$sqlcari,$gambar='gambar/judul-user.gif',$status='f',$muncul_divisi="",$tambahan_sql="",$template="",$fld_jumlah_1="",$fld_jumlah_2="",$caption_1="",$caption_2="",$muncul_tahun="",$kriteria_tambahan=""){
		global $src_kata;
		global $src_jenis,$nospk;
		global $cari;
		if ($status == ''){
			$status='f';
		}
		//echo kepala($gambar);
		echo bar_cari($sql,"",$muncul_divisi,$muncul_tahun);
		if($cari<>""){
			if ($src_kata <> ""){
				$result=dbresult($sqlcari);
				$fnum= pg_num_fields($result);
				if ($src_jenis == -1){
					for ($i=1; $i<=$fnum; $i++){
						$tambahan .= "lower(".pg_field_name($result, $i).") like lower('%$src_kata%') or ";
					}
					$tambahan = substr($tambahan,0,strlen($tambahan) - 3);
				}else{
					$j = $src_jenis;
					$tambahan = "lower(".pg_field_name($result, $j) .") like lower(('%$src_kata%'))";
				}
				if(strpos("$sql","where")>0){
					$sql = $sql ." and (". $tambahan .") $tambahan_sql";
				}else{
					$sql = $sql ." where ". $tambahan. $tambahan_sql;
				}
			}else{
				if(trim($tambahan_sql)<>""){
					if(strpos("$sql","where")>0){
						$sql = $sql ." and (true $tambahan_sql)";
					}else{
						$sql = $sql ." where true ". $tambahan_sql;
					}
				}
			}
		}
		$txtout.= tabel_view($sql,0,'','','#1A75BF','white','white',"100%","t",$sqlcari,$kriteria_tambahan,$template,$fld_jumlah_1,$fld_jumlah_2,$caption_1,$caption_2);
		return $txtout;
	}
function bar_cari($nm_table,$aksi){
	global $src_kata;
	global $src_jenis;
	//global $src_divisi;
	//global $src_tahun;
	global $cari;
	//global $arr_divisi;
	$bgheader  = "darkblue";
	$result=dbresult($nm_table);
	$fnum= pg_num_fields($result);
	$num = pg_num_rows($result);
	$txt = "<form action=$aksi? method=post class='formCari'>";
        $txt .= "<table width=100% border=0 align=center>";
        $txt .= "<tr>";
	$txt .= "<td align=right width=60%> <font face=arial size=2 color=navy><b>
		Search : <input type=text size=30 name=src_kata value='$src_kata'> In : <select name=src_jenis><option value=-1>All</option>";
	for ($i=0; $i < $fnum - 6; $i++){
		if($i == $src_jenis){
			$txt .= "<option value=$i selected>".pg_field_name($result, $i)."</option>";
		}else{
			$txt .= "<option value=$i>".pg_field_name($result, $i)."</option>";
		}
	}
	$txt .= "</select>";
//	if($muncul_divisi <>""){
//		$txt .= "
//			Divisi : ".combo_array_new("src_divisi",$arr_divisi,$src_divisi)." Tahun :".combo_array_new("src_tahun",array("All"=>"All","2002"=>"2002","2003"=>"2003","2004"=>"2004","2005"=>"2005","2006"=>"2006","2007"=>"2007","2008"=>"2008","2009"=>"2009","2010"=>"2010"),$src_tahun)." ";
//	}
//	if($muncul_tahun <>""){
//		$txt .= " Tahun :".combo_array_new("src_tahun",array("2002"=>"2002","2003"=>"2003","2004"=>"2004","2005"=>"2005","2006"=>"2006","2007"=>"2007","2008"=>"2008","2009"=>"2009","2010"=>"2010"),$src_tahun)." ";
//	}

	$txt .= "</b></td>";
        $txt .= "<td align=left width=40%><input type=submit value=Go name=cari class='tombol'></font></td>";
        $txt .= "</tr></table></form>";
	return $txt;
}

function tabel_view($nm_table,$id,$link="/balifocus/tea_admin.php",$obj="",$bgjudul="ffffff",$warnatulisan="000000",$bgisi="ffffff",$width = "100%",$kondisi="t",$sqlcari="",$kreteria_tambahan="",$template="",$fld_jumlah_1="",$fld_jumlah_2="",$caption_1="",$caption_2=""){
	global $REQUEST_URI;
//	global $mode,$nospk;
//	global $permisi;
	global $obj;
	global $kode;
	global $cari,$src_divisi,$src_tahun;
	global $cusername;
	global $awalan;
	global $order,$sql_propinsi,$spl_prop;
	global $src_kata;
	global $src_jenis;
//	global $subbidang,$propinsi;
	$jumlah_per_hal = 20;
	//echo $nm_table;
	if($awalan==""){
		$awalan = 0;
		$next = $awalan + 1;
	}else{
		$awal_prev = $awalan - 1;
		$next=$awalan + 1;
	}
	$awalan_sql = $awalan * $jumlah_per_hal;
	$bgheader  = "darkblue";
	$result=dbresult($nm_table);
	$result=dbresult($nm_table);
	$result_cari=dbresult($sqlcari);
	$jumlah = pg_num_rows($result);
	if($order==""){
		$order = pg_field_name($result_cari,1);
	}
	$result=dbresult($nm_table ." order by ".$order." limit ".$jumlah_per_hal." offset ".$awalan_sql);
	//cari_subjumlah
	$fnum= pg_num_fields($result);
	$num = pg_num_rows($result);
	//echo $nm_table;
	$jml=ceil($jumlah/$jumlah_per_hal);
	$jmlakhir=$jml-1;
	$link_cari="&src_kata=$src_kata&src_jenis=$src_jenis&src_divisi=$src_divisi&src_tahun=$src_tahun&cari=$cari";
	if($jumlah > $jumlah_per_hal){
		if($awalan==0){
			$kata2="<font face=arial size=2 color=blue><a href=$link?awalan=$next$link_cari><img src=../gambar/tombol-nex.gif alt=\"Halaman Berikutnya\" width=18 height=18 border=0></a> &nbsp;<a href=$link?awalan=$jmlakhir$link_cari><img src=../gambar/tombol-last.gif alt=\"Halaman Akhir\" width=18 height=18 border=0></a></font>";
		}else{
			$kata1="<a href=$link?awalan=0$link_cari><img src=../gambar/tombol-first.gif alt=\"Halaman Akhir\" width=18 height=18 border=0></a> &nbsp;<font face=arial size=2 color=blue><a href=$link?awalan=$awal_prev$link_cari><img src=../gambar/tombol-pret.gif alt=\"Halaman Sebelumnya\" width=18 height=18 border=0></a></font>";
			if($awalan<($jml-1)){
				$kata2="<font face=arial size=2 color=blue><a href=$link?awalan=$next$link_cari><img src=../gambar/tombol-nex.gif alt=\"Halaman Berikutnya\" width=18 height=18 border=0></a> &nbsp;<a href=$link?awalan=$jmlakhir$link_cari><img src=../gambar/tombol-last.gif alt=\"Halaman Akhir\" width=18 height=18 border=0></a></font>";
			}
		}
	}
	$txt = "<table width=$width border=0 align=center>";
//	if($subbidang<>"" and $propinsi<>""){
//		$tmbhlink="&subbidang=$subbidang";
//		$tmbhlink1="&propinsi=$propinsi";
//	}
//	if($nospk<>""){
//		$tmbhspk="&nospk=$nospk";
//	}
//	if(isset($cusername)){
		/*
		$txt .= "<tr><td colspan=".($jml_colom+1)." bgcolor=#1A75BF><table width=100%><tr><td width=50%>";
		if($permisi["add"]=="izin"){
			$txt .= "<a href=\"$link?mode=add&obj=$obj$tmbhspk$tmbhlink$tmbhlink1&kode=$kode$kreteria_tambahan\"> <img src=../gambar/tombol-add.gif border=0></a>";
		}
		$txt .= "</td><td width=50% align=right>$kata1 $kata2</td></tr></table></td></tr>";
		*/
//	}
	$txt .= "<tr><td align=center bgcolor=#eeeeee><table width=$width border=0 cellpadding=1 cellspacing=1 bgcolor=#d0ebf6><tr bgcolor=$bgheader>";
	$txt .= "<td bgcolor=$bgjudul valign=top align=center width=30><font color=\"#FFFFFF\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\"><b>NO</b></font></td>";
	for ($i=0; $i <=$fnum; $i++){
		if($kondisi=="t"){
			if($i <> $id){
				if($i<$fnum){
					$str_order="&order=".pg_field_name($result_cari, $i);
				}
				$txt .= "<td bgcolor=$bgjudul valign=top align=center><a href=$link?$link_cari$str_order style='TEXT-DECORATION: none'><font color=\"#FFFFFF\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\"><b>".pg_field_name($result, $i)."</b></font></a></td>";
			}
		}else{
			$txt .= "<td bgcolor=$bgjudul valign=top align=center><a href=$link?order=".pg_field_name($result_cari, $i)." style='TEXT-DECORATION: none'><font face=verdana size=2 color=white><b>"
				.pg_field_name($result, $i)."</b></font></a></td>";
		}
	}
	$txt .= "</tr>";

	$txt .= "<tr bgcolor=#1A75BF><td valign=top align=center><font color=\"#FFFFFF\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">1</font></td>";
	for ($i=0; $i <= $fnum; $i++){
		if($kondisi=="t"){
			if($i <> $id){
				if($i<$fnum-1){
#	$str_order="&order=".odbc_field_name($result_cari, $i);
				}
				$txt .= "<td valign=top align=center><font color=\"#FFFFFF\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">".(1+$i)."</font></td>";
			}
		}else{
			$txt .= "<td bgcolor=$bgjudul valign=top align=center><font face=verdana size=2 color=white>".(1+$i)."</font></td>";
		}
	}
	$txt .= "</tr>";
	$jml = pg_num_rows($result);
	$jml_colom = pg_num_fields($result);
	$i=0;
	while(pg_fetch_row($result) ) {
		//for ($i=0; $i<$jml; $i++){
		if($warna_isi=="#E8EFFF"){
			$warna_isi="#ffffff";
		}else{
			$warna_isi="#E8EFFF";
		}
		$txt.= "<tr bgcolor=$warna_isi>";
		$txt .= "<td valign=top align=center><font size=1 face=\"Verdana, Arial, Helvetica, sans-serif\">".($awalan_sql+$i+1)."</font></td>";
		for ($j=1; $j<=pg_num_fields($result); $j++){
			$txt .= "<td valign=top><font size=1 face=\"Verdana, Arial, Helvetica, sans-serif\">".pg_result($result,$j)."</font></td>";
		}
		$i=$i+1;
		$txt .="</tr>";
	}
	if($subbidang<>"" and $propinsi<>""){
		$tmbhlink="&subbidang=$subbidang";
		$tmbhlink1="&propinsi=$propinsi";
	}
	if($nospk<>""){
		$tmbhspk="&nospk=$nospk";
	}
//	if(isset($cusername)){
		$txt .= "<tr><td colspan=".($jml_colom+1)." bgcolor=#1A75BF><table width=100%><tr><td width=50%>";
		if($permisi["add"]=="izin"){
			$txt .= "<a href=\"$link?mode=add&obj=$obj$tmbhspk$tmbhlink$tmbhlink1&kode=$kode$kreteria_tambahan\"> <img src=../gambar/tombol-add.gif border=0></a>";
		}
		$txt .= "</td><td width=50% align=right>$kata1 $kata2</td></tr></table></td></tr>";
//	}
	$txt .= "</table></td></tr></table><div align=center></div>";
	return $txt;
	}

function e_getTotalDay($tahun,$bulan,$hari){
    if ($bulan==2){
        if ($tahun%4==0 && $hari>29){
            $hari = 29;
        }else if($tahun%4!=0 && $hari>28){
            $hari = 28;
        }
    }else if(($bulan==4 || $bulan==6 || $bulan==9 || $bulan==11) && $hari>30){
        $hari = 30;
    }
    return $hari;
}

function e_getIpAddr(){
    if (!empty($_SERVER['HTTP_CLIENT_IP'])){ // check ip from share internet
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    }
    else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ // check ip is pass from proxy
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else{
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

function e_getDateNow(){
    return date("Y-m-d");
}

function e_getTimeNow(){
    return date("H:i:s");
}

function e_getDMYOnly($no,$control){
    if (strtolower($control)=='tahun'){
        $x='Y';
    }
    if(strtolower($control)=='bulan'){
        $x='n';
    }
    if (strtolower($control)=='tanggal'){
        $x='j';
    }
    $tanggal = date("$x");
    //$tanggalhsl = $no.$tanggal;
    return $tanggal;
}



function alertMsg($message, $form)
{
	echo "
		<script>
		alert('$message');
		window.location=('$form');
		</script>
		";
}
function location($form)
{
	echo "
		<script>
		window.location=('$form');
		</script>
		";
}
function getRSq($query) {
        global $conn;
	global $db;
        if(!isset($conn)){
		while(list($key,$isi)=each($db)){
			$opt .= "$key=$isi ";
		}
		$conn = pg_connect($opt);
	}

        $sql = pg_exec($conn, $query) or die(pg_errormessage($conn)."| ERROR : ".$query);
        //$rs = mysql_fetch_array($sql);
        //if($rs != "") {
        //    $temp = $rs;
        //}
        return $sql;
    }
//function getRSq($query) {
//        global $conn;
//	global $db;
//        if(!isset($conn)){
//                $conn = odbc_connect("Driver={PostgreSQL ODBC Driver(UNICODE)};Server=localhost;Database=$db[dbname]","$db[user]","$db[password]");
//		//$conn = odbc_connect("$db[dbname]","$db[user]","$db[password]");
//	}
//
//        $sql = odbc_exec($conn, $query) or die(odbc_error()."| ERROR : ".$query);
//        //$rs = mysql_fetch_array($sql);
//        //if($rs != "") {
//        //    $temp = $rs;
//        //}
//        return $sql;
//    }
function getRS($query) {
        $temp = "";
        global $conn;
	global $db;
        if(!isset($conn)){
		while(list($key,$isi)=each($db)){
			$opt .= "$key=$isi ";
		}
		$conn = pg_connect($opt);
	}
        $sql = pg_exec($conn, $query) or die(pg_errormessage($conn)."| ERROR : ".$query);
        $rs = pg_fetch_array($sql);
        if($rs != "") {
            $temp = $rs;
        }
        return $temp;
    }
//    function getRS($query) {
//        $temp = "";
//        global $conn;
//	global $db;
//        if(!isset($conn)){
//                $conn = odbc_connect("Driver={PostgreSQL ODBC Driver(UNICODE)};Server=localhost;Database=$db[dbname]","$db[user]","$db[password]");
//		//$conn = odbc_connect("$db[dbname]","$db[user]","$db[password]");
//	}
//        $sql = odbc_exec($conn, $query) or die(odbc_error()."| ERROR : ".$query);
//        $rs = odbc_fetch_array($sql);
//        if($rs != "") {
//            $temp = $rs;
//        }
//        return $temp;
//    }

    function kdauto($tabel,$inisial){
	$struktur = getRSq("SELECT DISTINCT * from $tabel");
	$field = pg_field_name($struktur,0);
	//$panjang = pg_field_len($struktur,1);
        //$panjang = pg_field_size($struktur,0);
        $panjang = 6;

	$qry = getRSq("SELECT max(".$field.") as id from ".$tabel);
        //echo "SELECT max(".$field.") as id from ".$tabel;
	$row = pg_fetch_array ($qry);

	if ($row['id']==""){
		$angka = 0;
		}else{
			$angka = substr($row['id'],strlen($inisial));
                        $angka = substr($angka,strlen("-"));
			}

	$angka++;
	$angka = strval($angka);
	$tmp = "";
	for ($i=1;$i<=($panjang-strlen($inisial)-strlen($angka)-1);$i++){
		$tmp = $tmp."0";
		}
		return $inisial."-".$tmp.$angka;
}

function getNameFromID($tabel,$fieldName,$fieldCond=""){
    $temp = "";
    if ($tabel!="" && $fieldName!=""){
    $rs = getRS("SELECT ".$fieldName." FROM ".$tabel." WHERE $fieldName!='' ".$fieldCond."");
    if ($rs!=""){
        $temp = $rs[$fieldName];
    }
    }
    return $temp;
}

function getQSearch($SQL,$SQLcari,$txtSearch,$Order,$Offset,$Limit,$tbSearch){
$sqlq = getRSq($SQLcari);
$jmlField = pg_num_fields($sqlq);
for ($x=1;$x<=$jmlField;$x++){
    $namaField = pg_field_name($sqlq, $x);
    $cond .= "lower(CAST(".$namaField." as TEXT)) LIKE lower('%$txtSearch%') OR ";
}
$condition = substr($cond,0,strlen($cond)-3);
// end field search
if(isset($tbSearch)){
	 $SQL .= " AND ($condition)";
         $SQL .= " ORDER BY $Order ASC";
         $SQL .= " OFFSET $Offset LIMIT $Limit ";
 }else{
         $SQL .= " ORDER BY $Order ASC";
         $SQL .= " OFFSET $Offset LIMIT $Limit ";
 }

 //$SQLtot = $SQL.$SQL1;
 return $SQL;
}

function getCari($sql,$sqlcari,$tambahan_sql=""){
    global $cari;
    global $src_kata;
    global $src_jenis;
    
    echo bar_cari($sql,"");
		if($cari<>""){
			if ($src_kata <> ""){
				$result=dbresult($sqlcari);
				$fnum= pg_num_fields($result);
				if ($src_jenis == -1){
					for ($i=0; $i<$fnum; $i++){
						$tambahan .= "lower(".pg_field_name($result, $i).") like lower('%$src_kata%') or ";
					}
					$tambahan = substr($tambahan,0,strlen($tambahan) - 3);
				}else{
					$j = $src_jenis;
					$tambahan = "lower(".pg_field_name($result, $j) .") like lower(('%$src_kata%'))";
				}
				if(strpos("$sql","where")>0){
					$sql = $sql ." and (". $tambahan .") $tambahan_sql";
				}else{
					$sql = $sql ." where ". $tambahan. $tambahan_sql;
				}
			}else{
				if(trim($tambahan_sql)<>""){
					if(strpos("$sql","where")>0){
						$sql = $sql ." and (true $tambahan_sql)";
					}else{
						$sql = $sql ." where true ". $tambahan_sql;
					}
				}
			}
		}
                //$temp .= tabel_view($sql,0,'','','#1A75BF','white','white',"100%","t",$sqlcari,$kriteria_tambahan,$template,$fld_jumlah_1,$fld_jumlah_2,$caption_1,$caption_2);
                return $sql;
}

function gridView($SQL,$SQLcari,$kontrol,$targettambah){
global $cari;

$dataperhal = 10;
    if(isset($_GET['page'])){
        $noPage= $_GET['page'];}
    else{
        $noPage= 1;
    }
$start = ($noPage-1)*$dataperhal;

    if ($kontrol!=""){
                $strkontrol ="<td><div align='center'>".$kontrol."</div></td>";
            }
    if ($targettambah!=""){
                $strtambah ="<form name='form1' method='post' action='".$targettambah.".php'>
                    <td height='30' width='45%'>
                      <input type='submit' name='Submit' value='Tambah Data' class='tombol'>
                    </td>
                    </form>";
    }
    $temp = "<table width='98%' height='90%' border='0' align='center' cellpadding='0' cellspacing='0'>
            <tr>
            <td height='30' valign='top' colspan='2'>
            <table width='100%' height='31' border='0' align='center' cellpadding='0' cellspacing='0'>
            <tr>
            <td height='30' valign='top'><img src='../../gambar/jdl-coa.gif' width='191' height='30'></td>
            </tr>
            <tr>
            <td height='1' bgcolor='#6699ff'><img src='../../gambar/0.gif' width='1' height='1'></td>
            </tr>
            </table></td>
            </tr><br>
            <tr>
            <td valign='top' colspan='2'>
            <table class='tabelViewInside' width='98%' cellspacing='1' cellpadding='0'>
            <tr>
            <td class='headerCari'>";
                $SQLtot = getCari($SQL,$SQLcari);
                if (isset($cari)){
                    $SQLtot = $SQLtot." OFFSET $start LIMIT $dataperhal";
                }else{
                    $SQLtot = $SQL." OFFSET $start LIMIT $dataperhal";
                }
                $rs = getRS($SQLtot);
   $temp .= "</td>
            </tr>
            <tr>
            <td><div class='scroll' align='center'>
            <table class='tabelIsi' width='1330px' cellpadding='0' cellspacing='1'>
            <tr bgcolor='#1A75BF'>";
            $resultF=dbresult($SQL);
            $fnum= pg_num_fields($resultF);
            for ($i=1; $i <= $fnum-2; $i++){
		$temp .="<th height='25'>".strtoupper(odbc_field_name($resultF, $i))."</th>";
            }

     $temp .="</tr>";

if ($rs!=""){
        $warna = '#FFFFFF';
        $result = getRSq($SQLtot);
	while($r=pg_fetch_array($result)){
            if ($warna == '#FFFFFF'){
                $warna = '#E8EFFF';
            }else{
                $warna = '#FFFFFF';
            }

//            if ($kontroledit=="Y"){
//                $kontrol .= "<a href='tambah-leveransir.php?action=edit&kdubah=".$r['id_leveransir']."'><img src='../../gambar/page_edit.gif' alt='Edit Data' width='20' height='20' border='0'></a>";
//                }
//            if ($kontroldelete=="Y"){
//                $kontrol .="<a href='procces-leveransir.php?action=delete&kddelete=".$r['id_leveransir']."' onclick=\"return confirm('Anda Yakin Akan Menghapus Data Ini!!!')\"><img src='../../gambar/page_delete.gif' alt='Delete Data' width='20' height='20' border='0'></a>";
//            }


        $temp .="<tr bgcolor=".$warna.">
            <td class='isiGrid'>&nbsp;".$r['id_leveransir']."</td>
            <td class='isiGrid'>&nbsp;".$r['nama_leveransir']."</td>
            <td class='isiGrid'>&nbsp;".$r['npwp_leveransir']."</td>
            <td class='isiGrid'>&nbsp;".$r['alamat_leveransir']."</td>
            <td class='isiGrid'>&nbsp;".$r['entry_by']."</td>
            <td class='isiGrid'>&nbsp;".$r['entry_date']."</td>
            <td class='isiGrid'>&nbsp;".$r['update_by']."</td>
            <td class='isiGrid'>&nbsp;".$r['update_date']."</td>
            ".$strkontrol."
            </tr>
            ";
}
}
       $temp .="<tr>
                <td height='1' colspan=".$jmlKolom." bgcolor='#6699ff'></td>
                </tr>
              </table>
              </div>
              </td>
              </tr>
              </table>
              </td>
              </tr>
              <tr bgcolor='#60B0EE'>";


       $temp = $temp.$targettambah;
//       $temp .="<form name='form1' method='post' action="tambah-leveransir.php">
//                    <td height="30" width="45%">
//                      <input type="submit" name="Submit" value="Tambah Data" class="tombol">
//                    </td>
//            </form>";

        $temp .="<td class='border-nopage'>";
        $qry = $SQL;
        $result=dbresult($qry);
        $jumData=pg_num_rows($result);
        $jumPage = ceil($jumData/$dataperhal);
        $showPage = 0;
        if ($noPage > 1) echo  "<a href='".$_SERVER['PHP_SELF']."?page=".($noPage-1)."'>PREV</a>";
        for($page = 1; $page <= $jumPage; $page++)
        {
                 if ((($page >= $noPage-2) && ($page <= $noPage + 2)) || ($page == 1) || ($page == $jumPage))
                {
                    if (($showPage == 1) && ($page != 2))  echo "...";
                    if (($showPage != ($jumPage - 1)) && ($page == $jumPage))  echo "...";
                    if ($page == $noPage) echo " <b>".$page."</b> ";
                    else echo " <a href='".$_SERVER['PHP_SELF']."?page=".$page."'>".$page."</a> ";
                    $showPage = $page;
                 }
        }
        if ($noPage < $jumPage) echo "<a href='".$_SERVER['PHP_SELF']."?page=".($noPage+1)."'>NEXT</a>";
   $temp .="</td>
            </tr>
            </table>";

   return $temp;
}

?>
